package com.fas.core.web.taglib;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.apache.commons.lang.StringUtils;

import com.fas.core.constant.R;
import com.fas.core.util.datadict.DataDicKit;

public class DictTag extends TagSupport {

	private static final long serialVersionUID = -1388619584068930286L;

	private String group;
	private String id;
	private String name;
	private String value;
	private String cssClass;
	
	@SuppressWarnings("unchecked")
	@Override
	public int doStartTag() throws JspException {
		JspWriter out = pageContext.getOut();
		
		Long corpid =  R.Const.SUPER_CORPID;
		//LoginUser loginUser =(LoginUser)this.pageContext.getSession().getAttribute(Keys.LOGIN_USER);
		//corpid = loginUser.getCorpid();
		
		StringBuffer selectHtml = new StringBuffer();
		selectHtml.append("<span ");
		if(StringUtils.isNotBlank(cssClass)){
			selectHtml.append(" class='").append(cssClass).append("'");
		}
		selectHtml.append(">");
		try{
		        if (group instanceof String) {
		        	String definition = (String) group;
		        	if (StringUtils.isNotBlank(definition) 
		        			&& (definition.startsWith(DataDicKit.me().getDictPrefix()))){
		        		
		        		String selectText = DataDicKit.me().getDictItemNameByCode(definition, value,corpid);
		        		
		        		selectHtml.append(selectText);
		        		
		    		}
		        }
				selectHtml.append("</span>");
		        out.print(selectHtml.toString());
		}catch(Exception e){
			e.printStackTrace();
		}
		

		return super.doStartTag();
	}
	
	
	public String getGroup() {
		return group;
	}


	public void setGroup(String group) {
		this.group = group;
	}


	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getValue() {
		return value;
	}
	public void setValue(String value) {
		this.value = value;
	}
	public String getCssClass() {
		return cssClass;
	}
	public void setCssClass(String cssClass) {
		this.cssClass = cssClass;
	}
	
}
